package com.mallcai.bigdata.ladon.service.peekdata.impl;


import com.mallcai.bigdata.ladon.dpl.entity.peekdata.ModelSchema;
import com.mallcai.bigdata.ladon.dpl.mapper.peekdata.ModelSchemaMapper;
import com.mallcai.bigdata.ladon.dpl.vo.DataType;
import com.mallcai.bigdata.ladon.service.peekdata.IModelSchemaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-06-26 20:07
 */
@Service
public class ModelSchemaService implements IModelSchemaService {

    @Autowired
    private ModelSchemaMapper modelSchemaMapper;

    @Override
    public List<ModelSchema> getByParams(Map<String, Object> params) {
        List<ModelSchema> modelSchemaList = modelSchemaMapper.getByParams(params);
        modelSchemaList.stream().filter(modelSchema -> StringUtils.isNoneBlank(modelSchema.getDataType()))
                .filter(modelSchema -> StringUtils.isNoneBlank(modelSchema.getFieldName()))
                .forEach(modelSchema ->{
            //暂时简单处理,后期这里需要根据不同的数据源对具体的类型做适配
            modelSchema.setDataType(DataType.parse(modelSchema.getDataType()).getCode());
        });
        return modelSchemaList;
    }
}
